import mysql from 'mysql';

/*连接池*/
const pool= mysql.createPool({
    connectionLimit : 10,
    host:'localhost',
    user:'root',
    password:'123456',
    database:'demo'
});

/*
*  Promise 对象可以理解为一次将要执行的操作（常常被用于异步操作）
* */


/*
* 输出常量query
*       return ...argv
*              |---new promise() 对象 作用解决嵌套调用
* */
export const query = (...argv) => new Promise(

        (resolve, reject) => {
        const args = [...argv, (error, rows) => {
            //判断状态是否异常
            if (error) return reject(error);
            resolve(rows)
        }];
        pool.query(...args);
    }

);

